//
//  GGTHeadTableViewCell.m
//  GGT
//
//  Created by 空空空 on 14/11/5.
//  Copyright (c) 2014年 GGT. All rights reserved.
//

#import "GGTHeadTableViewCell.h"
#import "GGTDeleteLabel.h"
#import "UIImageView+WebCache.h"
@implementation GGTHeadTableViewCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        self.currentPrice = [[UILabel alloc]init];
        [self.contentView addSubview:self.currentPrice];
        self.listPrice= [[GGTDeleteLabel alloc]init];
        [self.contentView addSubview:self.listPrice];
        self.imgView = [[UIImageView alloc]init];
        [self.contentView addSubview:self.imgView];
    }
    return self;
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    [self.imgView setImageWithURL:[NSURL URLWithString:self.GGTTeamBuyDetail.image] placeholderImage:[UIImage imageNamed:@"hold.png"]];

    self.listPrice.text = [NSString stringWithFormat:@"￥%@", self.GGTTeamBuyDetail.list_price];
    
    self.currentPrice.text = [NSString stringWithFormat:@"%@", self.GGTTeamBuyDetail.current_price];
    self.currentPrice.font = [UIFont fontWithName:@".HelveticaNeueInterface-Regular" size:40.00];
    self.currentPrice.textColor = [UIColor orangeColor];
    
    self.imgView.frame = CGRectMake(0, 0, self.contentView.frame.size.width, self.contentView.frame.size.height / 3 * 2);
    
    UILabel *symbol = [[UILabel alloc]initWithFrame:CGRectMake(10, self.contentView.frame.size.height / 3 * 2 + 20, self.contentView.frame.size.width / 16, self.contentView.frame.size.height / 7)];
    symbol.text = @"￥";
    symbol.textColor = [UIColor orangeColor];
    [self.contentView addSubview:symbol];
    
    
    self.currentPrice.frame = CGRectMake(self.contentView.frame.size.width / 14, self.contentView.frame.size.height / 3 *  2 + 15, self.contentView.frame.size.width / 3, self.contentView.frame.size.height / 5);
    
    
    
    if (self.currentPrice.text.length > 2) {
        self.listPrice.frame = CGRectMake(self.contentView.frame.size.width / 10 + self.contentView.frame.size.width / 5, self.contentView.frame.size.height / 3 * 2 + 30, self.contentView.frame.size.width / 5, self.contentView.frame.size.height / 12);
    } else {
       self.listPrice.frame = CGRectMake(self.contentView.frame.size.width / 10 + self.contentView.frame.size.height / 4, self.contentView.frame.size.height / 3 * 2 + 30, self.contentView.frame.size.width / 5, self.contentView.frame.size.height / 12);
    }
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.frame = CGRectMake(self.contentView.frame.size.width / 5 * 3, self.contentView.frame.size.height / 3 * 2 + 10, self.contentView.frame.size.width / 3, self.contentView.frame.size.height / 4);
    [button setTitle:@"立即抢购" forState:UIControlStateNormal];
    button.tintColor = [UIColor whiteColor];
    button.backgroundColor = [UIColor orangeColor];
    [button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:button];
    
}
- (void)buttonClick:(UIButton *)button
{
//注册通知中心
    NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
    [center postNotificationName:@"webView" object:self.GGTTeamBuyDetail.deal_id userInfo:nil];
}
- (void)dealloc
{
    [_currentPrice release];
    [_listPrice release];
    [_imgView release];
    [_GGTTeamBuyDetail release];
    [super dealloc];
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
